class Permuter {
int count
def swap (list, x, y) {
    def z = list[x]
    list[x] = list[y]
    list[y] = z
    list
}

def rotL(list, start) {
    def temp = list[start]
    def n = list.size()
    for (i in start..<n-1) {
        list[i] = list[i+1]
    }
    list[n-1] = temp
}

void permute(list, start) {
    if (999999 <= count && count <= 1000002) {
        println list.join()
    }
    if (count > 1000005) return
    count++
    def n = list.size()
    if (start < n) {
        for (i in n-1..start) {
            for (j in i+1..<n) {
                swap(list, i, j)
                permute(list, i+1)
            }
            rotL(list, i)
        }
    }
}
}
p = new Permuter()
p.permute([0,1,2,3,4,5,6,7,8,9], 0)
p.count

